package com.jz.netthings.core.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.*;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * @author yyy
 * @ClassName AdscmWebConfig
 * @Description springMvc 相关配置
 * @date 2018/8/3 14:54
 */
@Configuration
@EnableWebMvc
public class AdscmWebConfig extends WebMvcConfigurerAdapter {

    /**
     * 解决跨域问题
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        File path = null;
        try {
            path = new File(ResourceUtils.getURL("classpath:").getPath());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        String gitPath=path.getParentFile().getParentFile().getParent()+ File.separator+"adscm"+File.separator+"uploads"+File.separator;
        registry.addResourceHandler("/adscm/uploads/**").addResourceLocations(gitPath);
       // registry.addResourceHandler("/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/static/");
        super.addResourceHandlers(registry);
    }

}
